#include<iostream>
using namespace std;
int j = 0;

struct Num {
	int number;
	Num* next;
};
Num* Create(int* arr) {
		Num* head = new Num;
		Num* p1 = new Num;
		Num* p2 = new Num;
		int n = 0;
		p1->number = arr[j++];
		while (p1->number != -1) {
			n++;
			if (n == 1) {//连上头结点
				head->next = p1;
				p1->next = NULL;//尾巴置空
			}
			else
			{
				p2->number = arr[j++];
				if (p2->number != -1) {
					head->next = p2;
					p2->next = p1;
					p1 = p2;
					p2 = new Num;
				}
				else
					break;
			}	
		}
		return head;
}
void Delete(Num* head,int del) {
	Num* p1 = head;
	Num* p2 = head;
	while (p1->next != NULL) {
		p2 = p1;
		p1 = p1->next;
		if (p1->number == del) {
			p2->next = p1->next;
			break;
		}
	}
}
void Print(Num* head) {
	Num* p = head;
	while (p->next != NULL) {
		cout << p->next->number << ' ';
		p = p->next;
	}
}
int main() {
	int arr[10] = { 0 };
	int i = 0;
	while (1) {
		cin >> arr[i];
		if (arr[i] == -1) {
			break;
		}
		i++;
	}
	int del = 0;
	cin >> del;
	//创建链表
	Num* head = Create(arr);
	//删除某个元素
	Delete(head,del);
	//打印
	Print(head);
	return 0;
}